#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010;
struct S
{
	int d1, m1, y1;
	int d, m, y;
}s[N];
bool cmp(S a, S b)
{
	if (a.y != b.y) {
		return a.y < b.y;	
	}
	else {
		if (a.m != b.m) {
			return a.m < b.m;
		}
		else {
			return a.d < b.d;
		}
	}
}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b, c;
		scanf_s("%d/%d/%d", &a, &b, &c);
		s[i] = { a,b,c,a,b,c };
		if (a <= 12 && b <= 12) {
			if (a < b) {
				s[i] = { a,b,c,b,a,c };
			}
		}
		else if (a <= 12) {
			s[i] = { a,b,c,b,a,c };
		}
	}
	sort(s, s + n, cmp);
	for (int i = 0; i < n; i++) {
		printf("%02d/%02d/%04d\n", s[i].d1, s[i].m1, s[i].y1);
	}
	return 0;
}